package com.hll.api.controller.xinhua;

import com.hll.api.config.web.RespMessage;
import com.hll.api.service.XinhuaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 搜索
 *
 * @author 74172
 * @create 2019-07-10 23:39
 */
@RestController
@RequestMapping("/api/xinhua/search")
public class SearchController {
	@Resource
	XinhuaService service;

	/**
	 * 搜索框热门搜索关键字
	 */
	@GetMapping("/find/words")
	public RespMessage findWords() {
		return RespMessage.success(service.getFindWords(), null);
	}

	/** 搜索框提示 **/
	@GetMapping("/prompt")
	public RespMessage prompt(String keyword){
		if (StringUtils.isEmpty(keyword)){
			return RespMessage.error("搜索关键字：keyword 不能为空");
		}
		return RespMessage.success(service.getPrompt(keyword), null);
	}

	@GetMapping("/list")
	public RespMessage searchList(@RequestParam(name = "pageNo",defaultValue = "1")Integer pageNo,
	                              @RequestParam(name = "pageSize",defaultValue = "20")Integer pageSize,
	                              @RequestParam(name = "includeEbook",defaultValue = "true")boolean includeEbook,
                                  String keyword,Float lowPrice,Float highPrice,Integer sort,String tenantId,
                                  String brandIds,String regionIds,String backCategoryIds,String frontCategoryId,
                                  String shopId,String shopCategoryId,String attributes,String ids,String types,
                                  String itemCode,Integer inStock){
		return RespMessage.success(service.getSearchList(pageNo,pageSize,includeEbook,keyword,lowPrice,highPrice,
				sort,tenantId,brandIds,regionIds,backCategoryIds,frontCategoryId,shopId,shopCategoryId,attributes,
				ids,types,itemCode,inStock), null);
	}
}
